# Open TG Channel

**Open TG Channel** is an unofficial handmade API for getting data of public Telegram channels without signing in.


## Installation

First you should be sure that python3 is installed on your system. If it is not installed, you should install it using the following commands:

#### for Debian/Ubuntu-based systems
```
apt update
apt install python3 python3-pip
```

#### for Arch-based systems
```
pacman -Syu
pacman -S python3 python3-pip
```

Next your step is an installing required python-libraries:
```
pip3 install bs4
pip3 install requests
```

Well. Clone git repository:

```
git clone https://notabug.org/32xjb7zqcwk5ftme6464efocj676d7vr/TG-Open-Channel.git

```
...And you are done!

## Usage

This project may be executed as single file or as library:

```
from Open-TG-Channel import *


def processing(message):  # prints messages from the latest to the oldest
    if 'text' in  message.__dict__:
        print('='*16)
        print('Message id:', message.metadata.get('id'))
        print('Message date:', message.metadata.get('date'))
        print('-'*16)
        print('Message text:', message.text)
        print('='*16, '\n')
```

## Data hierarhy
```
scraper <Scraper>
|
+ <Channel>
| + counters <dictionary>
| | + 'Subscribers': <string>
| | + 'Links'      : <string>
| | + 'Videos'     : <string>
| | + 'Photos'     : <string>
| | + 'Files'      : <string>
| |
| + title <string>
| + description <string>
| + image <string>
| + username <string>
|
+ channel <Channel>
| 
+ message <class Message> [temporary]
  + source <dictionary>
  | + 'title': <string>
  | + 'url'  : <string>
  |
  + text <string>
  |
  + media <tuple>
  | + <dictionary>
  | | + 'type'     : 'image' <string>
  | | + 'url'      : <string>
  | | 
  | + <dictionary>
  | | + 'type'     : 'audio' <string>
  | | + 'url'      : <string>
  | | + 'duration' : <string>
  | |
  | + <dictionary>
  |   + 'type'     : 'video' <string>
  |   + 'url'      : <string>
  |   + 'duration' : <string>
  |   + 'thumbnail': <string>
  | 
  + file <dictionary>
  | + 'title': <string>
  | + 'extra': <string>
  |
  + poll <dictionary>
  | + 'title'  : <string>
  | + 'type'   : <string>
  | + 'answers': <tuple>
  | | + 'percent': <integer>
  | | + 'text'   : <string>
  | + 'voters' : <string>
  |
  + link_preview <dictionary>
  | + + 'url'         : <string>
  | | + 'site-preview': <dictionary>
  | |   + 'name'       : <string>
  | |   + 'thumbnail'  : <string>
  | |   + 'title'      : <string>
  | |   + 'description': <string>
  | |
  | + + 'url'         : <string> 
  |   + 'media'       : <dictionary>
  |     + <dictionary>
  |     | + 'type'     : 'image' <string>
  |     | + 'url'      : <string>
  |     | 
  |     + <dictionary>
  |       + 'type'     : 'video' <string>
  |       + 'url'      : <string>
  |       + 'duration' : <string>
  |       + 'thumbnail': <string>
  |
  + metadata <dictionary>
  | + 'id'    : <integer>
  | + 'date'  : <datetime.datetime>
  | + 'views' : <string>
  | + 'edited': <bool>
  |
  + keyboard <tuple>
    + <dictionary>
    + 'text': <string>
    + 'url' : <string>
```

## To-do list:
- add terminal arguments support
- fix URL chars replacing in question processing block